package com.huazi.www.user.cost.service.impl;

import com.huazi.www.user.cost.dao.UserDao;
import com.huazi.www.user.cost.dao.impl.UserImpl;
import com.huazi.www.user.cost.entity.UserEntity;
import com.huazi.www.user.cost.service.UserService;
import com.huazi.www.user.cost.util.Page;

import java.util.List;

public class UserServiceImpl implements UserService {

    /**
     * 查询用户缴费状态
     *
     * @return
     */
    @Override
    public int UserStateSelect_int() {
        UserDao dao = new UserImpl();
        int count = dao.UserStateSelect();
        return count;
    }

    /**
     * 分页查询
     *
     * @param currPageNo
     * @return
     */
    @Override
    public Page<UserEntity> UsetStateFengYeSelect(String name, Integer currPageNo) {
        Page<UserEntity> page = new Page<>();
        page.setCurrPageNo(currPageNo);
        page.setPageSize(6);
        UserDao dao = new UserImpl();
        int count = dao.UserTotalPageCount();
        page.setTotalPageCount(count);
        Integer start = (currPageNo - 1) * page.getPageSize();
        List<UserEntity> list = dao.UserSelect(name, start, page.getPageSize());
        page.setList(list);
        return page;
    }


    @Override
    public boolean userPaymentInsert_bool(Integer userId, UserEntity entity) {
        UserDao dao = new UserImpl();
        double money = dao.UserMoneySelect(userId);
        double price = dao.ctPrice(userId);
        int time = dao.userPaymentNbm(userId);
        double sum = price * time;
        int countInsert = 0;
        if (money > 0 && money > price) {
            countInsert = dao.userPaymentInsert(entity, userId, sum);
        }
        if (countInsert > 0) {
            return true;
        }
        return false;
    }

    @Override
    public Double UserMoneySelect_bool(Integer userId) {
        UserDao dao = new UserImpl();
        double money = dao.UserMoneySelect(userId);
        return money;
    }

    @Override
    public List<UserEntity> userPayment_bool(Integer userId) {
        UserDao dao = new UserImpl();
        List<UserEntity> list = dao.userPayment(userId);
        return list;
    }

//    @Override
//    public int userPaymentInsert_bool(UserEntity entity,Integer userId) {
//        UserDao dao=new UserImpl();
//        int count=dao.userPaymentInsert(entity,userId);
//        return count;
//    }

    @Override
    public boolean userStateUpdate_bool(Integer userId) {
        UserDao dao = new UserImpl();
        double money = dao.UserMoneySelect(userId);
        double price = dao.ctPrice(userId);
        int countUpdate = 0;
        if (money > 0 && money > price) {
            countUpdate = dao.userStateUpdate(userId);
        }
        if (countUpdate > 0) {
            return true;
        }
        return false;
    }
}
